//
//  CustomReportViewController.m
//  ForYourBeauty
//
//  Created by Kelly xu on 2019/6/2.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "CustomReportViewController.h"
#import "ReportTopCell.h"
#import "CustomReportCell.h"
#import "AnalysisViewController.h"
#import <UITableView+FDTemplateLayoutCell/UITableView+FDTemplateLayoutCell.h>
#import "ReportTextCell.h"
@interface CustomReportViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
}
@property(nonatomic,weak)IBOutlet UITableView *mainTableView;
@property(nonatomic,weak)IBOutlet UIButton *fenxiBtn;
@end

@implementation CustomReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"定制报告";
    self.fenxiBtn.layer.cornerRadius = 20;
    [self configTableView];
}
-(void)configTableView{
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    self.mainTableView.tableFooterView = [UIView new];
    [self.mainTableView registerNib:[UINib nibWithNibName:@"ReportTopCell" bundle:nil] forCellReuseIdentifier:@"ReportTopCell"];
    [self.mainTableView registerNib:[UINib nibWithNibName:@"CustomReportCell" bundle:nil] forCellReuseIdentifier:@"CustomReportCell"];
    [self.mainTableView registerNib:[UINib nibWithNibName:@"ReportTextCell" bundle:nil] forCellReuseIdentifier:@"ReportTextCell"];
    self.mainTableView.showsVerticalScrollIndicator = NO;
    self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.mainTableView.backgroundColor = [UIColor clearColor];
}
#pragma mark - UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (EC_ISNullStr(self.reportModel.reportResponse)) {
        return 2;
    }
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 1;
            break;
        case 1:
            return 2;
            break;
        case 2:
            return 1;
            break;
        default:
            return 0;
            break;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
            return 76;
            break;
        case 1:
            return 194;
            break;
        case 2:
            return [tableView fd_heightForCellWithIdentifier:@"ReportTextCell" configuration:^(id cell) {
                [self configCell:cell indexPath:indexPath];
            }];
            break;
        default:
            return 0;
            break;
    }
}
-(void)configCell:(ReportTextCell*)cell indexPath:(NSIndexPath*)indexPath{
    cell.reportText.text = [NSString stringWithFormat:@"%@",self.reportModel.reportResponse];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
        {
            ReportTopCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReportTopCell" forIndexPath:indexPath];
            cell.backgroundColor = [UIColor clearColor];
            cell.contentView.backgroundColor = [UIColor clearColor];
            [cell.bgView setImage:[[UIImage imageNamed:@"topBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"topBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"topBg"].size.height/2]];
            [cell setReportValue:self.reportModel];
            return cell;
        }
            break;
        case 1:
        {
            CustomReportCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomReportCell" forIndexPath:indexPath];
            cell.backgroundColor = [UIColor clearColor];
            cell.contentView.backgroundColor = [UIColor clearColor];
            if (indexPath.row<2-1){
                [cell.bgView setImage:[[UIImage imageNamed:@"middleBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"middleBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"middleBg"].size.height/2]];
                [cell setReportValue:self.reportModel isAfter:NO];
            }else{
                if (EC_ISNullStr(self.reportModel.reportResponse)) {
                    [cell.bgView setImage:[[UIImage imageNamed:@"bottomBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"bottomBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"bottomBg"].size.height/2]];
                }else{
                    [cell.bgView setImage:[[UIImage imageNamed:@"middleBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"middleBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"middleBg"].size.height/2]];
                }
                
                [cell setReportValue:self.reportModel isAfter:YES];
            }
            return cell;
        }
            break;
        case 2:
        {
            ReportTextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReportTextCell" forIndexPath:indexPath];
            cell.backgroundColor = [UIColor clearColor];
            cell.contentView.backgroundColor = [UIColor clearColor];
            [cell.bgView setImage:[[UIImage imageNamed:@"bottomBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"bottomBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"bottomBg"].size.height/2]];
            [self configCell:cell indexPath:indexPath];
            return cell;
        }
            break;
        default:
            return [UITableViewCell new];
            break;
    }
    
}
-(IBAction)fenxiBtnPressed:(id)sender{
    AnalysisViewController *fenxi = [[AnalysisViewController alloc]init];
    [self.rt_navigationController pushViewController:fenxi animated:YES complete:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
